# 多进程
from multiprocessing import Process

# 进程锁
from multiprocessing import Lock


from test_queue import RedisQueue,MysqlDb
from out_queue import doout

import time

# 实例化对象
mydb = MysqlDb()


locl = Lock()


# 异步出队方法
def doout(id):

	print(id)

	lock.acquire()

	#while 1:

	uid = rq.get_wait(1)

	if uid:

		# 修改字段  将审批人分配给 审批人   set auid = id where id = uid

		sql = " update `user` set `auid` = %s where `id` = %s " % (id,uid[1])

		print(sql)

		mydb.update(sql) 

		# time.sleep(1)

		print(uid[1])

	lock.release()


def dojob_process():

	# 查询审批人
	res = mydb.read_list(" select id from `user` where type = 2 order by rand() ")
	print(res)

	# 生成多进程容器
	plist = [Process(target=doout,args=(x["id"])) for x in res]

	[x.start() for x in plist]
	[x.join() for x in plist]


dojob_process()


